﻿var o = null;
$(function () {
    o = setInterval(function () {
        $(".mb1 a.go-next").click();
    }, 5000);
    setTimeout(function () {
        setInterval(function () {
            $(".mb2 a.go-next").click();
        }, 5000);
    }, 2500);

    $.fn.extend({
        simpleSlider: function (options) {
            var options = $.extend({}, options);

            return this.each(function () {
                var li = $('ul.boxRegion_inside li', this);
                var count = li.length;

                if (count <= 2) {
                    $('a.go-next, a.go-prev', this).remove();
                    return;
                }

                var nextBtn = $('a.go-next', this);

                nextBtn.parent().attr('rel', 0);

                $('a.go-next, a.go-prev', this).click(function () {
                    li.hide();
                    var parent = $(this).parent();
                    var index = parseInt($(this).parent().attr('rel'));

                    if ($(this).hasClass('go-next')) {

                        if (index + 2 >= count) {
                            index = -2;
                        }

                        for (var i = 0; i < 2; i++) {
                            li.eq(index + 2 + i).fadeIn();
                        }
                        var next = index + 2;
                        if (next >= count) {
                            next = 0;
                        }

                        parent.attr('rel', next);
                    }
                    else {
                        var mod;
                        if (index <= 0) {
                            mod = (count % 2);
                            if (mod == 0) {
                                index = count + 1;
                            }
                            else {
                                index = count + 1;
                            }
                        }
                        for (var i = 0; i < 2; i++) {
                            li.eq(index - 2 + i).fadeIn();
                        }
                        var prev = index - 2;
                        if (prev < 0) {
                            mod = (count % 2);
                            if (mod != 0) {
                                count += 1;
                            }
                            prev = count - 2;
                            //prev = Math.max(0, prev);
                        }

                        parent.attr('rel', prev);
                    }
                    return false;
                });
            });
        }
    });
    $(".boxRegion").simpleSlider();
});
